<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<HEAD>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<TITLE>Extensible 3D (X3D), ISO/IEC FCD 19775-1r1:200x, Annex K nVidia Cg shading language binding</TITLE>
<link href="X3D.css" type="text/css" rel=stylesheet>
</head>
<body>

<div class="CenterDiv">
<img class="x3dlogo" src="../Images/x3d.png" alt="X3D logo" style="width: 176px; height: 88px"> 
</div>

<div class="CenterDiv">
<p class="HeadingPart">
    Extensible 3D (X3D)<br />
    Part 1: Architecture and base components</p>

<p class="AnnexHeadingBottom">
    Annex K</p>

<p class="AnnexType">
        (normative)
<p class="AnnexHeadingBottom">
nVidia Cg shading language binding</p></div>

<img class="x3dbar" src="../Images/x3dbar.png" alt="--- X3D separator bar ---" width="430" height="23">

<h1><a name="General"></a>
<img class="cube" src="../Images/cube.gif" alt="cube" width="20" height="19"/>
K.1 General</h1>

<p>This annex defines the mapping of concepts of the Programmable shaders 
component to the nVidia Cg shading language (see
<a href="bibliography.html#[Cg]">[Cg]</a>). It applies to the ProgramShader, 
ShaderProgram and PackagedShader nodes with the <i>language</i> field set to 
&quot;Cg&quot;.

<h1><a name="Topics"></a>
<img class="cube" src="../Images/cube.gif" alt="cube" width="20" height="19"/>
K.2 Topics</h1>


<p><a href="#t-Topics">Table K.1</a> provides links to the major topics in this 
annex.</p>

<div class="CenterDiv">

<p class="TableCaption">
<a name="t-Topics"></a>
Table K.1 &#8212; Topics</p>

<table class="topics">
<tr> 
  <td> 
	<ul>
	  <li><a href="#General">K.1 General</a></li>
	  <li><a href="#Topics">K.2 Topics</a></li>
		<li><a href="#Concepts">K.3 Concepts</a><ul>
	  <li><a href="#RenderingAPISupportDifferences">K.3.1 Rendering API support 
		differences</a></li>
		<li><a href="#LanguageStrings">K.3.2 Language strings</a></li>
    </ul></li> 
	    <li><a href="#Interaction">K.4 Interaction with other nodes and components</a>
	    <ul>
		  <li><a href="#RenderingAPISupportDifferences">K.4.1 Vertex shader</a> 
		  <ul>
	    		  <li><a href="#VertexshaderOpenGL">K.4.1.1 OpenGL profiles</a></li> 
	    		  <li><a href="#VertexshaderDirect3D">K.4.1.2 Direct3D profiles</a></li> 
		  </ul></li>
		  <li><a href="#Fragmentshader">K.4.2 Fragment shader</a> 
		  <ul>
	    		  <li><a href="#FragmentshaderOpenGL">K.4.2.1 OpenGL profiles</a></li> 
	    		  <li><a href="#FragmentshaderDirect3D">K.4.2.2 Direct3D 
					profiles</a></li> 
		  </ul></li>
		  <li><a href="#Loadsensor">K.4.3 LoadSensor</a></li> 
		  <li><a href="#Vertexattributes">K.4.4 Vertex attributes</a> 
		  <ul>
	    		  <li><a href="#VertexattributesOpenGL">K.4.4.1 OpenGL profiles</a></li> 
	    		  <li><a href="#VertexattributesDirect3D">K.4.4.2 Direct3D 
					profiles</a></li> 
		  </ul></li>
		</ul>
	  </li> 
	  <li><a href="#Datatypemapping">K.5 Data type and parameter mappings</a>
	    <ul>
		  <li><a href="#Nodefields">K.5.1 Node fields</a></li> 
		  <li><a href="#Otherfields">K.5.2 X3D field types to Cg data types</a></li> 
		  <li><a href="#Worldstate">K.5.3 X3D world state to Cg parameter names</a></li> 
		</ul>
	  </li> 
	  <li><a href="#Eventmodel">K.6 Event model</a>
	    <ul>
		  <li><a href="#Changingurlfield">K.6.1 Changing URL fields</a></li>
		  <li><a href="#Changingattribfield">K.6.2 Changing the <i>attrib</i> 
			field</a></li>
		  <li><a href="#activatingprograms">K.6.3 Activating programs</a></li>
		</ul>
    </ul>
    <ul>
      <li><a href="#t-Topics">Table K.1 &#8212; Topics</a></li>
		<li><a href="#t-CgProfilemapping">Table K.2 &#8212; Language string to Cg 
		profile mapping</a></li>
	  <li><a href="#t-Direct3DVertexDeclarationUsage">Table K.3 &#8212; Supported 
		Direct3D vertex declaration usage types</a></li>
	  <li><a href="#t-X3DTextureTypeToCg">Table K.4 &#8212; Mapping of X3D texture 
		node types to Cg sampler types</a></li>
	  <li><a href="#t-X3DNodeTypeToCg">Table K.5 &#8212; Mapping of X3D material and 
		light node types to Cg structure declarations</a></li>
      <li><a href="#t-X3DFieldTypeToCg">Table K.6 &#8212; Mapping of X3D field types 
		to Cg data types</a></li>
      <li><a href="#t-X3DWorldStateToCg">Table K.7 &#8212; Mapping of X3D world state 
		to Cg parameter names</a></li>
	</ul>
  </tr>
</table>
</div>

<h1><a name="Concepts"></a>
<img class="cube" src="../Images/cube.gif" alt="cube" width="20" height="19"/>
K.3 Concepts</h1>


<h2><a name="RenderingAPISupportDifferences"></a>K.3.1 Rendering API support 
differences</h2>
<p>The Cg language is a diverse set of shading capabilities that aim to support 
programmable shaders for a variety of APIs. This part of ISO/IEC 19775 supports 
the OpenGL and Microsoft Direct3D APIs. Programming APIs may express the same 
concepts in very distinctly different ways and the two cited APIs do so. Thus, a 
Cg shader program written to work on OpenGL will not work on Direct3D. 
Conversely, a Cg shader program written to work on Direct3D will not work on 
OpenGL.</p>
<p>Cg handles the incompatible code problem by defining <i>Cg profiles</i>. A Cg 
profile is a set of available shading language functionality. At the time the 
browser downloads the file, it can use the profile information to guide how to 
compile the code to the appropriate target. This annex defines its behaviour 
based on the Cg profile specified by the user.</p>
<h2><a name="LanguageStrings"></a>K.3.2 Language strings</h2>
<p>Cg profile information is encoded as part of the language string of the 
ProgramShader node. All strings starting with &quot;CG-&quot; define behaviour defined in 
this annex. The part after the prefix defines the programming API and profile 
for which the Cg code shall be compiled. A browser thus may quickly distinguish 
which nodes to ignore and which to investigate further. The source files are 
referenced in the ShaderProgram nodes. This specification requires that the same 
profile is used for both the vertex and fragment programs.</p>
<p><a href="#t-CgProfilemapping">Table K.2</a> defines the mappings between the 
language string and the appropriate Cg profile. As Cg evolves, newer profiles 
may be defined and shall follow a similar naming convention.</p>

<div class=CenterDiv>
<p class="TableCaption">
<a name="t-CgProfilemapping"></a>
Table K.2 &#8212; Language string to Cg profile mapping</p>

<table class="topics" id="table1">
<tr> 
  <th>Language string</th>
  <th>Cg vertex shader profile</th>
  <th>Cg fragment shader profile</th>
<tr>
  <td>CG_OPENGL_ARB</td><td>CG_PROFILE_ARBVP1</td><td>CG_PROFILE_ARBFP1 </td>
</tr>
<tr>
  <td>CG_OPENGL_NV30</td><td>CG_PROFILE_VP30</td><td>CG_PROFILE_VP30</td>
</tr>
<tr>
  <td>CG_OPENGL_NV20</td><td>CG_PROFILE_VP20</td><td>CG_PROFILE_VP20</td>
</tr>
<tr>
  <td>CG_D3D_SHADER_2.0</td><td>CG_PROFILE_VS_2_0</td><td>CG_PROFILE_PS_2_0</td>
</tr>
<tr>
  <td>CG_D3D_SHADER_3.0</td><td>CG_PROFILE_VS_3_0</td><td>CG_PROFILE_PS_3_0</td>
</tr>
<tr>
  <td>CG_D3D_SHADER_1.3</td><td>CG_PROFILE_VS_1_3</td><td>CG_PROFILE_PS_1_3</td>
</tr>
</table>
</div>

<h1><a name="Interaction"></a>
<img class="cube" src="../Images/cube.gif" alt="cube" width="20" height="19"/>
K.4 Interaction with other nodes and components</h1>

<h2><a name="Vertexshader"></a>K.4.1 Vertex shader</h2>

<h3><a name="VertexshaderOpenGL"></a>K.4.1.1 OpenGL profiles</h3>
<p>The vertex shader replaces the fixed functionality of the vertex processor. 
The OpenGL specification states that the following functionality is disabled if 
a vertex shader is supplied:</p>
<ol type="a">
	<li>The model view matrix is not applied to vertex coordinates.</li>
	<li>The projection matrix is not applied to vertex coordinates. </li>
	<li>The texture matrices are not applied to texture coordinates. </li>
	<li>The normals are not transformed to eye coordinates. </li>
	<li>The normals are not rescaled or normalized.</li>
	<li>Texture coordinates are not generated automatically. </li>
	<li>Per-vertex lighting is not performed.</li>
	<li>Color material lighting is not performed. </li>
	<li>Point size distance attenuation is not performed. </li>
</ol>

<h3><a name="VertexshaderDirect3D"></a>K.4.1.2 Direct3D profiles</h3>

<p>In Cg language Direct3D profiles, the vertex shader replaces the vertex 
processing done by the Microsoft Direct3D graphics pipeline. While using a 
vertex shader, state information regarding transformation and lighting 
operations is ignored by the fixed-function pipeline. The Direct3D specification 
states that the following functionality is disabled if a vertex shader is 
supplied:</p>

<ol type="a">
	<li>The model view matrix is not applied to vertex coordinates.</li>
	<li>The projection matrix is not applied to vertex coordinates.</li>
	<li>The texture matrices are not applied to texture coordinates.</li>
	<li>The normals are not transformed to eye coordinates.</li>
	<li>The normals are not rescaled or normalized.</li>
	<li>Texture coordinates are not generated automatically.</li>
	<li>Per-vertex lighting is not performed.</li>
	<li>Color material lighting is not performed.</li>
	<li>Point size distance attenuation is not performed.</li>
</ol>

The fixed-function pipeline Direct3D graphics state is not available for use 
within a Cg shader program. Shaders that wish to make use of this data, such as 
material, lighting, texture and transformation matrix state, shall declare 
parameters of the appropriate type and pass values into them via declared fields 
of the containing ShaderProgram node in the X3D scene graph. The parameter types 
and mappings to those types from built-in X3D values are defined in
<a href="#Datatypemapping">K.4 Data type and parameter mappings</a>.

<h2><a name="Fragmentshader"></a>K.4.2 Fragment shader</h2>

<h3><a name="FragmentshaderOpenGL"></a>K.4.2.1 OpenGL profiles</h3>
<p>The fragment shader replaces the fixed functionality of the fragment 
processor. The OpenGL specification states that the following functionality is 
disabled if a fragment shader is supplied:</p>
<ol type="a">
	<li>Textures are not applied.</li>
	<li>Fog is not applied.</li>
</ol>

<h3><a name="FragmentshaderDirect3D"></a>K.4.2.2 Direct3D profiles</h3>

<p>In Cg language Direct3D profiles, the fragment shader, also known as a <i>
pixel</i> shader in Cg, replaces the fixed functionality of the Direct3D 
fragment processor. The Direct3D specification states that “textures are not 
applied” if a fragment shader is supplied.</p>The fixed function pipeline 
Direct3D graphics state is not available for use within a Cg pixel shader 
program. Shaders that wish to make use of this data, such as material, lighting, 
texture and transformation matrix state, shall declare parameters of the 
appropriate type and pass values into them via declared fields of the containing 
ShaderProgram node in the X3D scene graph. The parameter types and mappings to 
those types from built-in X3D values are defined in
<a href="#Datatypemapping">K.4 Data Type and Parameter Mappings</a>.

<h2><a name="Loadsensor"></a>K.4.3 LoadSensor</h2>

<p>The LoadSensor node (See <a href="components/networking.html#LoadSensor">9.4.3 
LoadSensor</a>) has two output fields 
<i>isActive</i> and <i>isLoaded</i>. The <i>isLoaded</i> field behaviour is 
unchanged.</p>

<p>The <i>isActive</i> field is defined to issue a <span class="code">TRUE</span> 
event when all the following conditions have been satisfied:</p>

<ol type="a">
	<li>The content identified by the <i>url</i> field has been successfully 
	loaded.</li>
	<li>The shader program has been successfully compiled without error.</li>
</ol>

<h2><a name="Vertexattributes"></a>K.4.4 Vertex attributes</h2>

<h3><a name="VertexattributesOpenGL"></a>K.4.4.1 OpenGL profiles</h3>
<p>Each vertex attribute node directly maps the <i>name</i> field to the uniform 
variable of the same name. If the name is not available as a uniform variable in 
the provided shader source, the values of the node shall be ignored. </p>
<p>The browser implementation shall automatically assign appropriate internal 
index values for each attribute</p>

<h3><a name="VertexattributesDirect3D"></a>K.4.4.2 Direct3D profiles</h3>

<p>In Cg language Direct3D profiles, each vertex attribute node directly maps 
the <i>name</i> field to a Direct3D usage type for use within a Direct3D vertex 
declaration (with the prefix &quot;<span class="code">D3DDECLUSAGE_</span>&quot; prepended 
to the name), as well as a Cg binding semantic of the same name defined on the 
varying inputs to a shader program. This language binding allows the use of the 
predefined Direct3D vertex declaration usage types and Cg binding semantics 
listed in <a href="#t-Direct3DVertexDeclarationUsage">Table K.3.</a>
If the name cannot be interpreted as a valid Direct3D usage type or Cg binding 
semantic, the values of the node shall be ignored.
</p>

<div class="CenterDiv">

<p class="TableCaption">
<a name="t-Direct3DVertexDeclarationUsage"></a>
Table K.3 &#8212; Supported Direct3D vertex declaration usage types</p>

<table>
<tr>
<th>Direct3D usage type</th>
</tr>
<tr>
  <td><i>POSITION</i></td>
</tr>
<tr>
  <td><i>NORMAL</i></td>
</tr>
<tr>
  <td><i>TEXCOORD</i></td>
</tr>
<tr>
  <td><i>TANGENT</i></td>
</tr>
<tr>
  <td><i>BINORMAL</i></td>
</tr>
<tr>
  <td><i>COLOR</i></td>
</tr>
<tr>
  <td><i>FOG</i></td>
</tr>
</table>
</div>

<p>The browser implementation shall automatically assign appropriate internal 
index values for each attribute in the case where multiple nodes are defined 
having the same value in the <i>name</i> field.</p>

<h1><a name="Datatypemapping"></a>
<img class="cube" src="../Images/cube.gif" alt="cube" width="20" height="19"/>
K.5 Data Type and Parameter Mappings</h1>

<h2><a name="Nodefields"></a>K.5.1 Node fields</h2>

<p>Fields that are of type SFNode/MFNode are ignored unless the value is of type
<i>X3DTextureNode</i>, or in Direct3D profiles, <i>X3DMaterialNode</i>, or <i>
X3DLightNode</i>. Field instances of type <i>X3DTextureNode</i> are mapped 
according to the appropriate Direct3D or OpenGL sampler data type. The mappings 
from texture nodes to built-in sampler types are defined in 
<a href="#t-X3DTextureTypeToCg">Table K.4</a>.

</p>

<div class="CenterDiv">

<p class="TableCaption">
<a name="t-X3DTextureTypeToCg"></a>
Table K.4 &#8212; Mapping of X3D texture node types to OpenGL or Direct3D sampler 
types</p>

<table>
<tr>
<th>X3D&nbsp;texture type</th>
<th>OpenGL variable type</th>
<th>Direct3D variable type</th>
</tr>
<tr>
  <td><i>X3DTexture2DNode</i></td>
  <td>sampler2D</td>
  <td>sampler2D</td>
</tr>
<tr>
  <td><i>X3DTexture3DNode</i></td>
  <td>sampler3D</td>
  <td>sampler3D</td>
</tr>
<tr>
  <td><i>X3DEnvironmentTextureNode</i></td>
  <td>samplerCube</td>
  <td>samplerCube</td>
</tr>
</table>
</div>

<p>X3D does not define mappings to the OpenGL types sampler1D, sampler1DShadow 
and sampler2DShadow or the Direct3D types sampler1D, sampler1DShadow and 
sampler2DShadow.</p>
<p>In Cg language OpenGL profiles, the current geometry and pipeline state is 
exposed through the built-in variable <i>glstate.</i></p>

<p>In Cg language Direct3D profiles, field instances of type <i>X3DMaterialNode</i> and 
<i>X3DLightNode</i> are mapped to structures that shall be declared in the 
shader program as defined in <a href="#t-X3DNodeTypeToCg">Table K.5</a>.</p>

<div class="CenterDiv">

<p class="TableCaption">
<a name="t-X3DNodeTypeToCg"></a>
Table K.5 &#8212; Mapping of X3D material and light node types to Cg structure 
declarations (Direct3D profiles only)
</p>

<table>
<tr>
<th>X3D&nbsp;node type</th>
<th>Cg structure declaration</th>
<th>Additional information</th>
</tr>
<tr>
  <td><i>X3DMaterialNode</i></td>
  <td>

<pre>
struct X3DMaterial {
    float4 diffuseColor;
    float4 ambientColor;
    float4 specularColor;
    float4 emissiveColor;
    float power;
};
</pre>

  </td>
  <td>
All color values are 4-component with alpha value = 1.0.</td>
</tr>
<tr>
  <td><i>X3DLightNode</i></td>
  <td>
<pre>
struct X3DLight {
    int type;
    float4 diffuseColor;
    float4 specularColor;
    float4 ambientColor;
    point3 position;
    point3 direction;
    float range;
    float falloff;
    float attenuation0;
    float attenuation1;
    float attenuation2;
    float theta;
    float phi;
    bool on;
};
</pre>
  </td>
  <td>
Valid <i>type</i> member values are 1 for Point light, 2 for Spot light and 3 
for Direction light.<p>All color values are 4-component with alpha value = 1.0.</p>
<p>All position, direction and scalar values are assumed to be in world space.</p>
<p>The <i>on</i> member specifies whether the light is enabled.<br>
  </td>
</tr>
</table>
</div>

<h2><a name="Otherfields"></a>K.5.2 X3D field types to Cg data types</h2>

<p><a href="#t-X3DFieldTypeToCg">Table K.6</a> indicates how the X3D field types 
shall be mapped to data types used in the Cg Language.</p>

<div class="CenterDiv">

<p class="TableCaption">
<a name="t-X3DFieldTypeToCg"></a>
Table K.6 &#8212; Mapping of X3D field types to Cg data types</p>

<table>
<tr>
<th>X3D&nbsp;Field type</th>
<th>Cg Data Type</th>
</tr>
<tr>
  <td>SFBool</td>
  <td>bool</td>
</tr>
<tr>
  <td>MFBool</td>
  <td>bool[]</td>
</tr>
<tr>
  <td>MFInt32</td>
  <td>float[]</td>
</tr>
<tr>
  <td>SFInt32</td>
  <td>float</td>
</tr>
<tr>
  <td>SFFloat</td>
  <td>float</td>
</tr>
<tr>
  <td>MFFloat</td>
  <td>float[]</td>
</tr>
<tr>
  <td>SFDouble</td>
  <td>double</td>
</tr>
<tr>
  <td>MFDouble</td>
  <td>double[]</td>
</tr>
<tr>
  <td>SFTime</td>
  <td>double</td>
</tr>
<tr>
  <td>MFTime</td>
  <td>double[]</td>
</tr>
<tr>
  <td>SFNode</td>
  <td>See <a href="#Nodefields">K.4.1 Node fields</a></td>
</tr>
<tr>
  <td>MFNode</td>
  <td>See <a href="#Nodefields">K.4.1 Node fields</a></td>
</tr>
<tr>
  <td>SFVec2f</td>
  <td>float2</td>
</tr>
<tr>
  <td>MFVec2f</td>
  <td>float2[]</td>
</tr>
<tr>
  <td>SFVec3f</td>
  <td>float3</td>
</tr>
<tr>
  <td>MFVec3f</td>
  <td>float3[]</td>
</tr>
<tr>
  <td>SFVec4f</td>
  <td>float4</td>
</tr>
<tr>
  <td>MFVec4f</td>
  <td>float4[]</td>
</tr>
<tr>
  <td>SFVec3d</td>
  <td>float3</td>
</tr>
<tr>
  <td>MFVec3d</td>
  <td>float3[]</td>
</tr>
<tr>
  <td>SFVec4d</td>
  <td>float4</td>
</tr>
<tr>
  <td>MFVec4d</td>
  <td>float4[]</td>
</tr>
<tr>
  <td>SFRotation</td>
  <td>float4</td>
</tr>
<tr>
  <td>MFRotation</td>
  <td>float4[]</td>
</tr>
<tr>
  <td>MFColor</td>
  <td>float4[]</td>
</tr>
<tr>
  <td>SFColor</td>
  <td>float4</td>
</tr>
<tr>
  <td>SFImage</td>
  <td>int[]</td>
</tr>
<tr>
  <td>MFImage</td>
  <td>int[]</td>
</tr>
<tr>
  <td>SFString</td>
  <td>Not supported</td>
</tr>
<tr>
  <td>MFString</td>
  <td>Not supported</td>
</tr>
<tr>
  <td>SFMatrix3f</td>
  <td>float3x3</td>
</tr>
<tr>
  <td>MFMatrix3f</td>
  <td>float3x3[]</td>
</tr>
<tr>
  <td>SFMatrix4f</td>
  <td>float4x4</td>
</tr>
<tr>
  <td>MFMatrix4f</td>
  <td>float4x4[]</td>
</tr>
</table>
</div>

<p>Cg defines maximum supported lengths of each array data type, which may 
conflict with the minimum support requirements for X3D.</p>

<h2><a name="Worldstate"></a>K.5.3 X3D world state to Cg parameter names</h2>

<p>In Cg language Direct3D profiles, certain internal states of the X3D world, 
such as transformation matrices, or the viewer&#39;s position in world space, are 
neither readily available via the Cg shader program or directly accessible from 
the X3D scene graph. Thus if used, these world state values shall be explicitly 
passed in to the shader program as named parameters. This binding defines an 
automatic mapping of these states to predefined shader program parameter names. <a href="#t-X3DWorldStateToCg">
Table K.7</a> 
specifies the mapping of internal states of the X3D world to parameter names 
used in the Cg programs.</p>

<div class="CenterDiv">

<p class="TableCaption">
<a name="t-X3DWorldStateToCg"></a>
Table K.7 &#8212; Mapping of X3D world state to Cg parameter names (Direct3D profiles 
only)</p>
<table>
<tr>
<th>Parameter name</th>
<th>Description</th>
</tr>
<tr>
  <td><b>model</b></td>
  <td>
This name refers to the matrix transforming from local to global coordinates. 
The model matrix transforms vertices from their model position to their position 
in world space (<i>i.e.</i>, after the effects of all Transform nodes have been 
applied).  
  </td>
</tr>
<tr>
  <td><b>view</b></td>
  <td>
This name refers to the viewing matrix transforming from world to view relative 
coordinates.
  </td>
</tr>
<tr>
  <td><b>projection</b></td>
  <td>
This name refers to the projection matrix transforming from viewing relative 
coordinates to clip space, including the projective part.
  </td>
</tr>
<tr>
  <td><b>modelView</b></td>
  <td>
This name refers to the matrix that represents the concatenation of model and 
view matrices. This matrix transforms vertices from their model position to 
their position in view space (<i>i.e.</i>, after the effects of all Transform 
nodes and the current viewpoint have been applied).  </td>
</tr>
<tr>
  <td><b>modelViewProjection</b></td>
  <td>
This name refers to the matrix that represents the concatenation of model, view 
and projection matrices. This matrix transforms vertices from their model 
position to their final position in clip space.  </td>
</tr>
<tr>
  <td><b>viewPosition</b></td>
  <td>
This name refers to the current viewer position in world space coordinates.</td>
</tr>
</table>
</div>

<p>
The following suffixes can be applied to the matrix built-in values. A suffix of <i>
I</i> signifies the inverse of the matrix. <i>T</i> signifies the transpose of 
the matrix. <i>IT</i> signifies the inverse transpose of the matrix.
</p> 

<h1><a name="Eventmodel"></a>
<img class="cube" src="../Images/cube.gif" alt="cube" width="20" height="19"/>
K.6 Event model</h1>

<h2><a name="Changingurlfield"></a>K.6.1 Changing URL fields</h2>

<p>When the <i>url</i> receives an event changing the value, the browser shall 
immediately attempt to download the new source. Upon successful download, the 
browser shall attempt to compile the new source and issue the appropriate 
LoadSensor events. It shall not automatically activate the shader program, nor 
disable the currently running shader.</p>

<p>Values defined at load time of the file do not require an explicit request to 
activate the shader program. It shall be assumed to automatically activate the 
program once all the objects have successfully downloaded. If some of the shader 
source files are not downloaded or compiled (<i>e.g.</i>, due to errors), no 
activation shall occur for the shader program.
</p>

<h2><a name="Changingattribfield"></a>K.6.2 Changing the <i>attrib</i> field</h2>

<p>Per-vertex attributes may be defined as one of the fields of 
<i>X3DComposedGeometryNode</i>. These may be changed at runtime by adding or 
removing node instances. Adding new node instances to the field shall require 
that the user request an explicit activate in order to make them visible to the 
shader.</p>

<h2><a name="activatingprograms"></a>K.6.3 Activating programs</h2>

<p>The user may, at any time, request that the browser activate the composing 
shader objects by sending a <span class="code">TRUE</span> value to the <i>
activate</i> inputOnly field of the ProgramShader or PackagedShader node. Users 
may need to force a re-activation of the node under various circumstances, such 
as changing the <i>url</i> field of one or more ShaderProgram or PackagedShader 
nodes, or adding or removing ShaderProgram nodes from the <i>programs</i>field 
of the ProgramShader node. Reactivating the shader shall replace the existing 
shader with the new compiled shader for subsequent rendering.</p>

<img class="x3dbar" src="../Images/x3dbar.png" alt="--- X3D separator bar ---" width="430" height="23">

</body>
</html>
